package de.jmda.home.ui.vaadin;

import de.jmda.common.ui.web.vaadin.service.DefaultSessionContext;
import de.jmda.home.ui.vaadin.uiarea.AreaBottomComponent;
import de.jmda.home.ui.vaadin.uiarea.AreaCenterComponent;
import de.jmda.home.ui.vaadin.uiarea.AreaLeftComponent;
import de.jmda.home.ui.vaadin.uiarea.AreaRightComponent;
import de.jmda.home.ui.vaadin.uiarea.AreaTopComponent;
import de.jmda.home.ui.vaadin.userguide.UserGuideChapterDisplayRequest;
import de.jmda.home.ui.vaadin.userguide.UserGuideDisplay.UserGuideChapter;

/**
 * Manages the areas of an application.
 *
 * @author rwegner
 */
public class MainUIComponentController
{
	private MainUIComponent component;
	
	public MainUIComponentController(MainUIComponent component)
	{
		super();

		this.component = component;

		initComponentAreas();

		DefaultSessionContext
				.get()
				.getEventBus()
		    .post(new UserGuideChapterDisplayRequest(UserGuideChapter.HOME));
	}

	private void initComponentAreas()
  {
		initTop();
		initLeft();
		initCenter();
		initRight();
		initBottom();
  }

	private void initTop()
	{
		component.getUIAreas()
		         .getTopCenterBottom()
		         .getTop()
		         .addComponent(new AreaTopComponent());
	}

	private void initLeft()
  {
		component.getUIAreas()
		         .getLeftCenterRight()
		         .getLeft()
		         .addComponent(new AreaLeftComponent());
  }

	private void initCenter()
  {
		component.getUIAreas()
		         .getLeftCenterRight()
		         .getCenter()
		         .addComponent(new AreaCenterComponent());
  }

	private void initRight()
  {
		component.getUIAreas()
		         .getLeftCenterRight()
		         .getRight().addComponent(new AreaRightComponent());
  }

	private void initBottom()
  {
		component.getUIAreas()
		         .getTopCenterBottom()
		         .getBottom().addComponent(new AreaBottomComponent());
  }
}